//
//  SortDetailViewController.m
//  项目
//
//  Created by 关雷 on 15-1-8.
//  Copyright (c) 2015年 张诗雨. All rights reserved.
//

#import "SortDetailViewController.h"
#import "AFNetWoringYu.h"
#import "UIScrollView+MJRefresh.h"
#import "WebColor.h"
#import "SortDetailModel.h"
#import "SortDetailUserModel.h"
@interface SortDetailViewController ()

@end

@implementation SortDetailViewController
- (void)dealloc
{
    [_table release];
    [_tableArray release];
    [_SortDetailUserArray release];
    [super dealloc];
}
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.tableArray = [NSMutableArray array];
        self.SortDetailUserArray = [NSMutableArray array];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self startConnectWithType:self.type];
    //http://api.pianke.me/read/category_detail
    //client=1&limit=10&sort=addtime&start=0&type=1
    //client=1&limit=10&sort=addtime&start=0&type=2
    // Do any additional setup after loading the view.
}
- (void)startConnectWithType:(NSInteger)type
{
    NSString * body = [NSString stringWithFormat:@"client=1&limit=10&sort=addtime&start=0&type=%ld", type];
    [AFNetWoringYu netWorkWithURL:@"http://api.pianke.me/read/category_detail" body:body resultBlock:^(id dic) {
        NSDictionary * data = [dic objectForKey:@"data"];
        NSArray * list = [data objectForKey:@"list"];
        for (NSDictionary * dics in list) {
            SortDetailModel * model = [[SortDetailModel alloc] init];
            [model setValuesForKeysWithDictionary:dics];
            SortDetailUserModel * userM = [[SortDetailUserModel alloc] init];
            [userM setValuesForKeysWithDictionary:model.userinfo];
            
            [_tableArray addObject:model];
            [_SortDetailUserArray addObject:userM];
        }
        [_table reloadData];
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
